#include "abstractdeck.h"
#include <klocalizedstring.h>
#include <kdebug.h>


AbstractDeck::AbstractDeck(QObject *parent) : QObject(parent)
{
    ;
}

int AbstractDeck::getCard(City city, Value value, bool isMultiplier)
{
    int returnCard = 0;
    if (isMultiplier)
    {
        returnCard = 13 * city + 10 + value;
    }
    else
    {
        returnCard = 13 * city + value;
    }
    return returnCard;
}

City AbstractDeck::getCity(int card)
{
    return (City)(card%5);
}

Value AbstractDeck::getValue(int card)
{
    int returnValue;
    returnValue = card/5;
    if (returnValue>9)
    {
        returnValue = returnValue - 10;
    }
    return (Value)returnValue;
}

bool AbstractDeck::isMultiplier(int card) {
    bool isMultiplier;
    int cardValue = card/5;
    if (cardValue>9) {
        isMultiplier=true;
    }
    else {
        isMultiplier=false;
    }
    return isMultiplier;
}

int AbstractDeck::cardsNumber() {
    return 13*5;
}

QString AbstractDeck::getName(City city)
{
    QString cityName; 
    switch (city)
    {
        case Atlantis:
            cityName = i18n("Atlantis");
            break;
        case Cibola:
            cityName = i18n("Cibola");
            break;
        case Aoudaghost:
            cityName = i18n("Aoudaghost");
            break;
        case Yamatai:
            cityName = i18n("Yamatai");
            break;
        case Karakorum:
            cityName = i18n("Karakorum");
            break;
        default:
            cityName = i18n("unknown");
    }
    return cityName;
}

QString AbstractDeck::getName(Value value, bool isMultiplier) {
    QString valueName;
    if (isMultiplier)
    {
        valueName = i18n("Multiplier");
    }
    else 
    {
        switch (value){
            case One:
                valueName = i18n("One");
                break;
            case Two:
                valueName = i18n("Two");
                break;
            case Three:
                valueName = i18n("Three");
                break;
            case Four:
                valueName = i18n("Four");
                break;
            case Five:
                valueName = i18n("Five");
                break;
            case Six:
                valueName = i18n("Six");
                break;
            case Seven:
                valueName = i18n("Seven");
                break;
            case Eight:
                valueName = i18n("Eight");
                break;
            case Nine:
                valueName = i18n("Nine");
                break;
            case Ten:
                valueName = i18n("Ten");
                break;
            default:
                valueName = i18n("Unknown");
        }
    }
    return valueName;
}

QString AbstractDeck::getName(City city, Value value, bool isMultiplier) {
    QString cityName = getName(city);
    QString valueName  = getName(value, isMultiplier);
    return i18nc("eg One of Cibola", "%1 of %2", valueName, cityName);
}

QString AbstractDeck::getName(int card) {
    City city = getCity(card);
    bool multiplier = isMultiplier(card);
    Value value = getValue(card);
    return getName(city, value, multiplier);
}

int AbstractDeck::remainingCards() {
    return m_cards.size();
}
